﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
namespace TuongLai_Schools
{
    public class cls_DM_Chitieudanhgiahanhkiem
    {
        public DataTable GetAll_Chitieudanhgiahanhkiem(int caphocid)
        {
            DbAccess db = new DbAccess();
            db.CreateNewSqlCommand_Text();
            DataTable dataTable = db.ExecuteDataTable("Select ChiTieuDanhGiaHanhKiemID,TenChiTieuDanhGiaHanhKiem,FK_CapHocID,isChangeable from DM_ChiTieuDanhGiaHanhKiem where FK_CapHocID="+ caphocid +"");
            return dataTable;
        }
        public DataTable GetAll_Caphoc()
        {
            DbAccess db = new DbAccess();
            db.CreateNewSqlCommand_Text();
            DataTable dataTable = db.ExecuteDataTable("Select ROW_NUMBER() OVER(ORDER BY TenCapHoc) as TT, CapHocID,TenCapHoc from DM_CapHoc");
            return dataTable;
        }
        public bool Insert(clsDM_Chitieudanhgiahanhkiem obj)
        {
            try
            {
                DbAccess db = new DbAccess();
                db.CreateNewSqlCommand_Text();
                db.AddParameter("@ChiTieuDanhGiaHanhKiemID", obj.ChiTieuDanhGiaHanhKiemID);
                db.AddParameter("@TenChiTieuDanhGiaHanhKiem", obj.TenChiTieuDanhGiaHanhKiem);
                db.AddParameter("@FK_CapHocID", obj.FK_CapHocID);
                db.AddParameter("@isChangeable", obj.isChangeable);
                db.ExecuteNonQuery("insert into DM_ChiTieuDanhGiaHanhKiem(TenChiTieuDanhGiaHanhKiem,FK_CapHocID,isChangeable) values(N'" + obj.TenChiTieuDanhGiaHanhKiem + "',N'" + obj.FK_CapHocID + "','" + obj.isChangeable + "')");
                return true;
            }
            catch
            {
                return false;
            }
        }
        public bool update(clsDM_Chitieudanhgiahanhkiem obj)
        {
            try
            {
                DbAccess db = new DbAccess();
                db.CreateNewSqlCommand_Text();
                db.AddParameter("@ChiTieuDanhGiaHanhKiemID", obj.ChiTieuDanhGiaHanhKiemID);
                db.AddParameter("@TenChiTieuDanhGiaHanhKiem", obj.TenChiTieuDanhGiaHanhKiem);
                db.AddParameter("@FK_CapHocID", obj.FK_CapHocID);
                db.AddParameter("@isChangeable", obj.isChangeable);
                db.ExecuteNonQuery("update DM_ChiTieuDanhGiaHanhKiem set TenChiTieuDanhGiaHanhKiem=N'" + obj.TenChiTieuDanhGiaHanhKiem + "',FK_CapHocID=" + obj.FK_CapHocID + ",isChangeable='" + obj.isChangeable + "' where ChiTieuDanhGiaHanhKiemID='" + obj.ChiTieuDanhGiaHanhKiemID + "'");
                return true;
            }
            catch
            {
                return false;
            }
        }
        public bool delete(int Chitieudanhgiahanhkiemid)
        {
            try
            {
                DbAccess db = new DbAccess();
                db.CreateNewSqlCommand_Text();
                db.AddParameter("@ChiTieuDanhGiaHanhKiemID", Chitieudanhgiahanhkiemid);
                db.ExecuteNonQuery("delete DM_ChiTieuDanhGiaHanhKiem where ChiTieuDanhGiaHanhKiemID='" + Chitieudanhgiahanhkiemid + "'");
                return true;
            }
            catch
            {
                return false;
            }
        }
    }
}
